#!/bin/bash

# 检查nginx进程是否正在运行
nginx_process=$(pgrep nginx)

if [ -z "$nginx_process" ]; then
  echo "Nginx进程未运行"
  echo "Nginx process is not running"
  exit 1
else
  echo "Nginx进程正在运行"
  echo "Nginx process is running"
fi

# 查询nginx的总请求数
total_requests=$(cat /usr/local/nginx/logs/access.log | awk '{print $7}' | wc -l)

echo "Nginx总请求数：$total_requests"
echo "Total number of Nginx requests: $total_requests"

# 查询nginx的并发连接数
concurrent_connections=$(cat /usr/local/nginx/logs/nginx.pid | wc -l)

echo "Nginx并发连接数：$concurrent_connections"
echo "Number of concurrent Nginx connections: $concurrent_connections"

# 查询nginx的内存使用情况
memory_usage=$(ps aux | grep nginx | grep -v grep | awk '{print $4}')

echo "Nginx内存使用情况：$memory_usage MB"
echo "Nginx memory usage: $memory_usage MB"

# 查询nginx的CPU使用情况
cpu_usage=$(ps aux | grep nginx | grep -v grep | awk '{print $3}')

echo "Nginx CPU使用情况：$cpu_usage%"
echo "Nginx CPU usage: $cpu_usage%"